#include "stdafx.h"

AnimationMgr::AnimationMgr()
{
}

AnimationMgr::~AnimationMgr()
{
	clear();
}

AnimationMgr * AnimationMgr::getInstance()
{
	static AnimationMgr animation_manager;

	return &animation_manager;
}

void AnimationMgr::create(const std::wstring & name, int num, int interval, int x, int y)
{
	anims.push_back(new Animation(L"img\\" + name, num, interval, x, y));
}

void AnimationMgr::update(double dtime)
{
	std::vector<Animation *>::iterator pani = anims.begin();

	while (pani != anims.end())
	{
		(*pani)->update(dtime);
		if ((*pani)->finished())
		{
			delete *pani;
			pani = anims.erase(pani);
		}
		else
		{
			pani++;
		}
	}
}

void AnimationMgr::draw(Graphics * graphics)
{
	for (Animation * ani : anims)
	{
		ani->draw(graphics);
	}
}

void AnimationMgr::clear()
{
	for (Animation * ani : anims)
	{
		delete ani;
	}

	anims.clear();
}